<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">

<!--添加提报计划模态框-->
<div class="modal fade" id="modal-create">
    <div class="modal-dialog" style="width:800px;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">添加提报计划</h4>
            </div>
            <div class="modal-body">
                <form id="createReportPlanForm" class="form-horizontal">
                    <div class="col-md-12">
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">物料描述</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="rppMatDesc" autocomplete="off" placeholder="物料描述">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">项目编号</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="rppProjectCode" autocomplete="off" placeholder="项目编号">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">项目名称</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="rppProjectName" autocomplete="off" placeholder="项目名称">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">计划员</label>
                                <div class="col-sm-8">
                                    <select class="form-control" name="rppPlanner" title="">
                                        <option th:each="planner : ${planners}" th:value="${planner.empName}" th:text="${planner.empName}"></option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">数量</label>
                                <div class="col-sm-8">
                                    <input type="number" step="0.1" class="form-control" name="rppNum" autocomplete="off" placeholder="数量">
                                </div>
                            </div>
                        </div>
<!--                        <div class="col-md-6">-->
<!--                            <div class="form-group">-->
<!--                                <label class="col-sm-4 control-label">实用数量</label>-->
<!--                                <div class="col-sm-8">-->
<!--                                    <input type="number" step="0.1" class="form-control" name="rppRealNum" autocomplete="off" placeholder="实用数量">-->
<!--                                </div>-->
<!--                            </div>-->
<!--                        </div>-->
<!--                        <div class="col-md-6">-->
<!--                            <div class="form-group">-->
<!--                                <label class="col-sm-4 control-label">余量</label>-->
<!--                                <div class="col-sm-8">-->
<!--                                    <input type="number" step="0.1" class="form-control" name="rppOverNum" autocomplete="off" placeholder="余量">-->
<!--                                </div>-->
<!--                            </div>-->
<!--                        </div>-->
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">单位</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="rppUnit" autocomplete="off" placeholder="单位">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">标准号</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="rppStandardNo" autocomplete="off" placeholder="标准号">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">品牌</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="rppBrand" autocomplete="off" placeholder="品牌">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">分类</label>
                                <div class="col-sm-8">
                                    <select class="form-control" name="rppTypeId" title="">
                                        <option th:each="type : ${categories}" th:value="${type.dicId}" th:text="${type.dicName}"></option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">计划号</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="rppPlanNo" autocomplete="off" placeholder="计划号">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">提报类型</label>
                                <div class="col-sm-8">
                                    <select class="form-control" name="rppUseStock" title="">
                                        <option value="">无状态</option>
                                        <option value="1">使用库存</option>
                                        <option value="2">正常提报</option>
                                        <option value="3">暂不提报</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">备注</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="rppRemark" autocomplete="off" placeholder="备注">
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" id="btn-create-report-plan">提交</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<!--导入提报计划模态框-->
<div class="modal fade" id="modal-import">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">Excel信息导入</h4>
            </div>
            <div class="modal-body">
                <form id="importForm">
                    <div class="form-group">
                        <label>模版</label>
                        <a th:href="@{/file/提报计划模板.xlsx}">点击下载</a>
                    </div>
                    <div class="form-group">
                        <label>上次导入错误数据</label>
                        <a id="download-error"
                           th:data-url="@{/files/{user}/error.xls(user=${session.user.account})}"
                           href="javascript:void(0);">点击下载</a>
                    </div>
                    <!--<div class="form-group">
                        <label for="yearMonth">生产日报上传年月份</label>
                        <input type="text" class="form-control col-md-3" id="yearMonth" name="yearMonth"
                               th:value="${#dates.format(date, 'yyyy-MM')}" readonly="readonly"/>
                    </div>-->
                    <div class="form-group">
                        <label>选择Excel文件并上传</label>
                        <input class="btn" type="file" multiple="multiple" name="file">
                        <p class="help-block">请按模板格式进行导入，信息与模板信息对应。</p>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button shiro:hasPermission="buy:planimport:add" id="btn-upload" type="button" class="btn btn-success">
                    <span class="Bold">上传</span>
                </button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<!--修改提报计划模态框-->
<div class="modal fade" id="modal-edit">
    <div class="modal-dialog" style="width:800px;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">修改提报计划</h4>
            </div>
            <div class="modal-body">
                <form id="editReportPlanForm" class="form-horizontal">
                    <input type="hidden" name="rppId">
                    <div class="col-md-12">
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">物料描述</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="rppMatDesc" autocomplete="off" placeholder="物料描述">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">计划员</label>
                                <div class="col-sm-8">
                                    <select class="form-control" name="rppPlanner" title="">
                                        <option th:each="planner : ${planners}" th:value="${planner.empName}" th:text="${planner.empName}"></option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">数量</label>
                                <div class="col-sm-8">
                                    <input type="number" step="0.1" class="form-control" name="rppNum" autocomplete="off" placeholder="数量">
                                </div>
                            </div>
                        </div>
<!--                        <div class="col-md-6">-->
<!--                            <div class="form-group">-->
<!--                                <label class="col-sm-4 control-label">实用数量</label>-->
<!--                                <div class="col-sm-8">-->
<!--                                    <input type="number" step="0.1" class="form-control" name="rppRealNum" autocomplete="off" placeholder="实用数量">-->
<!--                                </div>-->
<!--                            </div>-->
<!--                        </div>-->
<!--                        <div class="col-md-6">-->
<!--                            <div class="form-group">-->
<!--                                <label class="col-sm-4 control-label">余量</label>-->
<!--                                <div class="col-sm-8">-->
<!--                                    <input type="number" step="0.1" class="form-control" name="rppOverNum" autocomplete="off" placeholder="余量">-->
<!--                                </div>-->
<!--                            </div>-->
<!--                        </div>-->
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">单位</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="rppUnit" autocomplete="off" placeholder="单位">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">标准号</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="rppStandardNo" autocomplete="off" placeholder="标准号">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">品牌</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="rppBrand" autocomplete="off" placeholder="品牌">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">分类</label>
                                <div class="col-sm-8">
                                    <select class="form-control" name="rppTypeId" title="">
                                        <option th:each="type : ${categories}" th:value="${type.dicId}" th:text="${type.dicName}"></option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">计划号</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="rppPlanNo" autocomplete="off" placeholder="计划号">
                                </div>
                            </div>
                        </div>
                        <!--<div class="col-md-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">项目名称</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="rppProjectName" autocomplete="off" placeholder="项目名称">
                                </div>
                            </div>
                        </div>-->
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">提报类型</label>
                                <div class="col-sm-8">
                                    <select class="form-control" name="rppUseStock" title="">
                                        <option value="">无状态</option>
                                        <option value="1">使用库存</option>
                                        <option value="2">正常提报</option>
                                        <option value="3">暂不提报</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">备注</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="rppRemark" autocomplete="off" placeholder="备注">
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" id="btn-edit-report-plan">提交</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<!--修改计划员模态框-->
<div class="modal fade" id="modal-edit-planner">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">修改计划员</h4>
            </div>
            <div class="modal-body">
                <form id="editPlannerForm" class="form-horizontal">
                    <input type="hidden" name="rppId">
                    <div class="col-md-12">
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">计划员</label>
                                <div class="col-sm-8">
                                    <select class="form-control" name="rppPlanner" title="">
                                        <option th:each="planner : ${planners}" th:value="${planner.empName}" th:text="${planner.empName}"></option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" id="btn-edit-planner">提交</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>


<section class="content-header"><h1>提报计划导入</h1></section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" onsubmit="return false;">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label>物料描述</label>
                                    <input type="text" name="rppMatDesc" class="form-control" placeholder="请输入提报物料描述">
                                </div>
                                <div class="form-group">
                                    <label>项目编号</label>
                                    <input type="text" name="rppProjectCode" class="form-control" placeholder="请输入项目编号">
                                </div>
                                <div class="form-group">
                                    <label>项目名称</label>
                                    <input type="text" name="rppProjectName" class="form-control" placeholder="请输入项目名称">
                                </div>
                                <div class="form-group">
                                    <label>计划号</label>
                                    <input type="text" name="rppPlanNo" class="form-control" placeholder="请输入计划号">
                                </div>
                                <div class="form-group">
                                    <label>计划员</label>
                                    <input type="text" name="rppPlanner" class="form-control" placeholder="请输入计划员">
                                </div>
                                <!--<div class="form-group">
                                    <label>提报状态</label>
                                    <select name="rppUseStock" class="form-control">
                                        <option value="1">使用库存</option>
                                        <option value="2">正常提报</option>
                                        <option value="3">暂不提报</option>
                                        <option value="" selected="">全部</option>
                                    </select>
                                </div>-->
                                <div class="form-group">
                                    <label>分类</label>
                                    <select name="rppTypeId" class="form-control">
                                        <option value="" selected="selected">全部</option>
                                        <option th:each="type : ${categories}" th:value="${type.dicId}" th:text="${type.dicName}"></option>
                                    </select>
                                </div>
                                <div class="form-group" >
                                    <label>单据状态</label>
                                    <select name="rppStatus" class="form-control">
                                        <option value="">全部</option>
                                        <option value="-1" selected="selected">未提交</option>
                                        <option value="2">已提交</option>
                                        <option value="-2">已删除</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>导入日期</label>
                                    <input type="text" class="form-control datepicker" name="startTime" readonly="readonly"/>
                                    <span> 至 </span>
                                    <input type="text" class="form-control datepicker" name="endTime" readonly="readonly"/>
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search">
                                    <span class="Bold">搜索</span>
                                </button>
                            </div>

                        </div>
                    </form>
                    <div class="row" id="toolbar">
                        <div class="form-inline">
                            <a shiro:hasPermission="buy:planimport:add" href="javascript:void(0);" class="btn btn-primary pull-right" style="margin-right: 10px" onclick="openImportModal()">
                                <span class="Bold">导入</span>
                            </a>
                            <a shiro:hasPermission="buy:planimport:add" href="javascript:void(0);" class="btn btn-info pull-right" style="margin-right: 10px" onclick="openCreateModal()">
                                <span class="Bold">添加</span>
                            </a>
                            <a shiro:hasPermission="buy:planimport:del" href="javascript:void(0);" class="btn btn-danger pull-right" style="margin-right: 10px" onclick="deleteAll()">
                                <span class="Bold">全部删除</span>
                            </a>
                            <a shiro:hasPermission="buy:planimport:edit" href="javascript:void(0);" class="btn btn-success pull-right" style="margin-right: 10px" onclick="commitAll()">
                                <span class="Bold">全部提交</span>
                            </a>

                        </div>
                    </div>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">

    /** 表格 */
    var table;
    var reportState = ['','使用库存','正常提报','暂不提报','甲供'];
    var projectState = ['无状态','执行中','未开始','暂缓','已完成','取消'];
    var colors = ['',"label-warning", "label-default", "label-danger", "label-success"];
    var colors1 = ['',"label-warning", "label-info", "label-primary"];
    var infoUrl = ctx + 'buy/editReportPlan/info/';

    /** 打开导入模态框 */
    function openCreateModal() {
        js.modal.open("modal-create");
    }

    /** 打开导入模态框 */
    function openImportModal() {
        js.modal.open("modal-import");
    }

    /** 删除提报计划 */
    function deleteReportPlan(id) {
        js.confirmPost({
            content: "删除数据将无法恢复，确认删除吗？",
            url: ctx + "buy/importReportPlan/delete",
            data: {
                id: id
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(table);
                } else {
                    js.modal.warning(result.msg);
                }
            }
        });
    }
    /** 批量删除提报计划 */
    function deleteAll() {
        var arr = js.table.selectColumns(table, "rppId");
        if (arr.length < 1) {
            js.modal.warning("请选择要删除的计划");
            return;
        }
        js.post({
            url: ctx + "buy/importReportPlan/deleteAll",
            data: {
                rppIds: js.table.selectColumns(table, "rppId")
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(table);
                } else {
                    js.modal.warning(result.msg);
                }
            }
        })
    }

    /** 提交提报计划 */
    function commitReportPlan(id) {
        js.confirmPost({
            content: "确认提交吗？",
            url: ctx + "buy/importReportPlan/commit",
            data: {
                id: id
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(table);
                } else {
                    js.modal.warning(result.msg);
                }
            }
        });
    }
    /** 批量提交提报计划 */
    function commitAll() {
        var arr = js.table.selectColumns(table, "rppId");
        if (arr.length < 1) {
            js.modal.warning("请选择要提交的计划");
            return;
        }
        js.post({
            url: ctx + "buy/importReportPlan/commitAll",
            data: {
                rppIds: js.table.selectColumns(table, "rppId")
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(table);
                } else {
                    js.modal.warning(result.msg);
                }
            }
        })
    }

    /** 打开修改模态框 */
    function openEditReportPlanModal(row) {
        $("#editReportPlanForm").fillData(row);
        js.modal.open("modal-edit");
    }

    /** 打开修改计划员模态框 */
    function openEditPlannerModal(row) {
        $("#editPlannerForm").fillData(row);
        js.modal.open("modal-edit-planner");
    }

    $(function () {
        $("title").html($("title").html()+" —— 提报计划导入");
        /** 初始化表格 */
        table = js.table.init({
            url: ctx + "buy/importReportPlan/list",
            showColumns: false,
            showExport: false,
            pageSize: 300,
            paginationVAlign: 'both',
            columns: [
                {
                    checkbox: true,
                    width: '30px',
                    formatter: function (value, row, index) {
                        // 正常提报并且数据正常状态可以提交选择
                        if (row.rppStatus === -1) {
                            return {disabled: false}
                        } else {
                            return {disabled: true}
                        }
                    }
                },
                {
                    title: '序号', field: 'id', width: '50px',
                    formatter: function (value, row, index, field) {
                        return index + 1;
                    }
                },
                { title: "计划员", field: 'rppPlanner'},
                { title: "物料描述", field: 'rppMatDesc'},
                { title: "数量", field: 'rppNum'},
                // { title: "实用", field: 'rppRealNum'},
                // { title: "余量", field: 'rppOverNum'},
                { title: "单位", field: 'rppUnit'},
                { title: "标准号", field: 'rppStandardNo'},
                { title: "分类", field: 'rppTypes'},
                { title: "品牌", field: 'rppBrand'},
                { title: "备注", field: 'rppRemark', width: '60px'},
                { title: "项目编号", field: 'rppProjectCode'},
                { title: "项目名称", field: 'rppProjectName'},
                {
                    title: "提报状态", field: 'rppUseStock',
                    formatter: function (value, row, index) {
                        if (value) {
                            return '<span class="badge ' + colors1[value] + '">' + reportState[value] + '</span> ';
                        }
                    }
                },
                { title: "计划号", field: 'rppPlanNo'},
                { title: "提报日期", field: 'rppCreateTime', width: '90px'},
                {
                    title: "操作",
                    width: '110px',
                    formatter: function (value, row, index) {
                        var actions = [];
                        // 未提交状态
                        if (row.rppStatus === -1) {
                            if (hasP("buy:planimport:edit")) {
                                actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="openEditReportPlanModal(' + js.jsonStringify(row) + ')"> 修改</a> ');
                                actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="commitReportPlan(' + row.rppId + ')"> 提交</a> ');
                            }
                            if (hasP("buy:planimport:del")) {
                                actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="deleteReportPlan(' + row.rppId + ')"> 删除</a> ');
                            }
                        } else if (row.rppStatus === 2) {
                            if (hasP("buy:planimport:edit")) {
                                actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="openEditPlannerModal(' + js.jsonStringify(row) + ')"> 修改</a> ');
                            }
                        }
                        return actions.join('');
                    }
                }
            ]
        });
        /** 表格搜索 */
        $("#btn-search").click(function () {
            js.table.search(table);
        });


        /** 添加表单验证规则 */
        js.validate.init("createReportPlanForm", {
            fields: {
                rppProjectCode: {
                    validators: {
                        notEmpty: {message: '请输入项目编号'},
                        remote: {
                            url: ctx + "buy/importReportPlan/checkProjectCode",
                            message: '项目编号不存在',
                            delay: 500,
                            type: 'POST'
                        },
                    }
                },
                rppProjectName: {validators: {notEmpty: {message: '请输入项目名称'}}},
                rppMatDesc: {validators: {notEmpty: {message: '请输入物料描述'}}},
                rppNum: {validators: {notEmpty: {message: '请输入数量'}}},
                rppUnit: {validators: {notEmpty: {message: '请输入单位'}}},
            }
        });
        /** 添加模态框隐藏事件，重置表单，重置验证 */
        js.modal.hideEvent("modal-create", function () {
            js.validate.reset("createReportPlanForm");
            js.reset("createReportPlanForm");
        });
        /** 添加提报计划 */
        $("#btn-create-report-plan").click(function () {

            js.validSubmit({
                formId: "createReportPlanForm",
                url: ctx + "buy/importReportPlan/create",
                data: new FormData($("#createReportPlanForm")[0]),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                        js.modal.hide("modal-create");
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            });
        });



        /** 导入表单验证规则 */
        js.validate.init("importForm", {
            fields: {
                file: {
                    validators: {
                        notEmpty: {message: '上传文件不能为空'},
                        file: {extension: 'xls,xlsx', message: '请选择excel文件'}
                    }
                }
            }
        });
        /** 导入模态框隐藏事件，重置表单，重置验证 */
        js.modal.hideEvent("modal-import", function () {
            js.validate.reset("importForm");
            js.reset("importForm");
        });
        /** 导入提报计划 */
        $("#btn-upload").click(function () {
            var $this = $(this);
            $this.attr('disabled', true);
            js.validSubmit({
                formId: "importForm",
                url: ctx + "buy/importReportPlan/import",
                data: new FormData($("#importForm")[0]),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        if (result.msg == '导入完成') {
                            js.modal.hide("modal-import");
                        }
                        js.table.refresh(table);
                        $this.attr('disabled', false);
                    }
                }
            });
        });


        /** 下载导入失败excel */
        $("#download-error").click(function () {
            var that = $(this);
            js.post({
                url: ctx + "buy/editReportPlan/exist",
                async: false,
                data: {
                    url: that.attr("data-url")
                },
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        that.attr("href", that.attr("data-url") + "?timeStamp=" + new Date().getTime());
                    } else {
                        js.modal.warning("没有需要处理的文件");
                    }
                }
            });
        });


        /** 修改表单验证规则 */
        js.validate.init("editReportPlanForm", {
            fields: {
                rppMatDesc: {validators: {notEmpty: {message: '请输入物料描述'}}},
                rppProjectName: {validators: {notEmpty: {message: '请输入项目名称'}}},
                rppNum: {validators: {notEmpty: {message: '请输入数量'}}},
                rppUnit: {validators: {notEmpty: {message: '请输入单位'}}}
            }
        });
        /** 修改提报计划模态框隐藏事件， 重置表单，重置验证 */
        js.modal.hideEvent("modal-edit", function () {
            js.validate.reset("editReportPlanForm");
            js.reset("editReportPlanForm");
        });
        /** 修改提报计划 */
        $("#btn-edit-report-plan").click(function () {

            js.validSubmit({
                formId: "editReportPlanForm",
                url: ctx + "buy/importReportPlan/edit",
                data: new FormData($("#editReportPlanForm")[0]),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                        js.modal.hide("modal-edit");
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            });
        });

        /** 修改计划员 */
        $("#btn-edit-planner").click(function () {
            js.submit({
                url: ctx + "buy/importReportPlan/edit",
                data: new FormData($("#editPlannerForm")[0]),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                        js.modal.hide("modal-edit-planner");
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            });
        });

    });

</script>
</body>
</html>
